﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AnimEditor.Anim;
using AnimEditor.Picture;
using AnimEditor.Define;
using AnimEditor.Tile;

namespace AnimEditor
{
    public partial class MakeTileForm : Form
    {
      MainForm pForm = null;
      MakeTileData mMakeTileData = new MakeTileData();
      public MakeTileForm(MainForm form)
        {
            InitializeComponent();
            pForm = form;
            propertyGrid1.SelectedObject = mMakeTileData;
        }

        public MakeTileData MakeTileData
        {
          get { return mMakeTileData; }
          set { mMakeTileData = value; }
        }

        private void Btn_Create_Click(object sender, EventArgs e)
        {
          int col = MakeTileData.GridSize.Width;
          int row = MakeTileData.GridSize.Height;
          if (col > 0 && row > 0)
          {
            AnimPoint CurPoint = new AnimPoint(MakeTileData.StartPoint.X, MakeTileData.StartPoint.Y);
           
            for (int i = 0; i < row; i++)
            {
              for (int j = 0; j < col; j++ )
              {
                TileMgr.Instance.Tile_Sprites.Add(
                  new TileData(Rectangle.FromLTRB(CurPoint.X, CurPoint.Y, CurPoint.X + MakeTileData.TileSize.Width, CurPoint.Y+MakeTileData.TileSize.Height),
                    string.Format("Tile{0}", TileMgr.Instance.Tile_Sprites.Count))
                  );

                CurPoint.X += MakeTileData.TileSize.Width;
              }
              CurPoint.X = MakeTileData.StartPoint.X;
              CurPoint.Y += MakeTileData.TileSize.Height;
            }
            pForm.GetLstTiles().DataBindings.Clear();
            pForm.GetLstTiles().DataSource = null;
            pForm.GetLstTiles().DataSource = TileMgr.Instance.Tile_Sprites;
            pForm.GetLstTiles().DisplayMember = "Name";

          }
          pForm.GetGridPanel().Invalidate();
          this.Close();
        }

        private void propertyGrid1_PropertyValueChanged(object s, PropertyValueChangedEventArgs e)
        {
          this.propertyGrid1.Refresh();
        }
    }
}
